package com.sc.nft.entity.req;

import cn.hutool.core.convert.Convert;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sc.nft.entity.CollectionGift;
import com.sc.nft.entity.DaoWallet;
import com.sc.nft.entity.UserChainInfo;
import com.sc.nft.entity.UserInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 朱梦晨
 * @Description:
 * @date 2024-10-22
 */
@Data
public class CollectionGiveDaoRequest {


    @ApiModelProperty("转增方手机号")
    private String giftUserTel;


    @ApiModelProperty("接收方手机号")
    private String receiveUserTel;

    @ApiModelProperty("daoId")
    private Long daoId;


    @ApiModelProperty("赠送的藏品id")
    private Long id;

    //@ApiModelProperty("支付密码")
    //private String paymentPass;

    @ApiModelProperty("赠送地址")
    private String address;

    @ApiModelProperty("支付方式  1.星球碎片 2.余额 3.生态燃料")
    private Integer consumeType;

    @ApiModelProperty("用户数据")
    @JsonIgnore
    private UserInfo userInfo;

    @ApiModelProperty("赠送人地址")
    @JsonIgnore
    private UserChainInfo giftUserChainInfo;

    @ApiModelProperty("受赠送人地址")
    @JsonIgnore
    private UserInfo complimentarySubscriber;

    //@ApiModelProperty("赠送人的钱包")
    //@JsonIgnore
    //private UserWallet userWallet;

    @ApiModelProperty("dao的钱包")
    private DaoWallet daoWallet;


    @ApiModelProperty("所需钱")
    @JsonIgnore
    private BigDecimal amount;

    @ApiModelProperty("短信验证码")
    private String verifyCode;

    @ApiModelProperty("数量")
    private Integer count;

    @ApiModelProperty("操作人id")
    private Long operatorId;



    /**
     * 密码验证器
     *
     * @return
     */
    /*public void passwordVerifier() {
        if (!this.userInfo.getTransactionPassword().equals(this.paymentPass)) {
            throw new GlobalRunTimeException("密码错误");
        }
    }*/

    public Boolean selfDenial(){
        if (this.giftUserChainInfo.getAddress().equals(this.address)) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    public void calculate(List<CollectionGift> list, Integer sum) {
        BigDecimal amo = BigDecimal.ZERO;
        for (CollectionGift gift : list) {
            if (gift.getConsumeType().equals(2)) {
                amo = amo.add(Convert.toBigDecimal(gift.getQuantityConsume()).multiply(Convert.toBigDecimal(sum)));
            }
        }
        this.amount = amo;
    }


}
